<?php
declare (strict_types = 1);

namespace app\admin\controller;

use think\facade\Db;

/**
 * @note 管理员操作日志
 * @author liujian
 * Class AdminLog
 * @package app\admin\controller
 * @Create Date : 2021年04月01日 下午1:57:18
 */
class AdminLog extends Base
{
    /**
     * @OA\Get(path="/adminLog/list",
     *   tags={"管理员管理"},
     *   summary="管理员操作日志列表",
     *   @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string", default="123456")),
     *   @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="int", default="1")),
     *   @OA\Parameter(name="page_size", in="query", description="行数", @OA\Schema(type="int", default="10")),
     *   @OA\Parameter(name="search", in="query", description="关键词", @OA\Schema(type="string", default="")),
     *   @OA\Parameter(name="start_time", in="query", description="开始时间", @OA\Schema(type="string", default="")),
     *   @OA\Parameter(name="end_time", in="query", description="结束时间", @OA\Schema(type="string", default="")),
     *   @OA\Response(
     *      response=200,
     *      description="The Member",
     *      @OA\JsonContent(type="object",
     *          @OA\Property(property="msg", type="string"),
     *          @OA\Property(property="code", type="integer", default="200"),
     *          @OA\Property(property="data", type="object",
     *               @OA\Property(property="list", type="object",description="列表,具体值参考详情"),
     *          ),
     *      ),
     *   ),
     * )
     */
    public function list(int $page_size=10)
    {
        $where = [];
        if (!empty(input("search"))) {
            $where[] = ['realname', 'like', "%".input("search")."%"];
            $where[] = ['content', 'like', "%".input("search")."%"];
        }
        if (!empty(input("start_time")) && !empty(input("end_time"))) {
            $where[] = ['create_time', '<', input("end_time")];
            $where[] = ['create_time', '>', input("start_time")];
        }
        //
        $list = Db::name("admin_log")
            ->where($where)
            ->order("id","desc")
            ->paginate($page_size)
            ->each(function ($item, $key) {
                $item['content'] = u2c($item['content']);
                return $item;
            });
        return $this->jsonSuccessData("获取成功", [
            "list" => $list
        ]);
    }

}
